﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NHunspell;

namespace TP2
{
    class Program
    {
        static void Main(string[] args)
        {
            // poner en Repo Fallas I\TP 2\Proyecto\TP2\TP2\bin\Debug
            // los .dll de HNunspell
            // y el archivo 'entry.txt' que quieran parsear y Stem-mear

            var outputFile = new StreamWriter(@"output.txt");
            var hunspell = new Hunspell("es_ES.aff", "es_ES.dic");

            var lines = File.ReadAllText(@"entry.txt", Encoding.Default).Split(new[] { '\n' });
            foreach( var line in lines )
            {
                var words = line.Split(new[] {' '});
                foreach (var word in words)
                {
                    string outputLine = "";
                    var filteredWord = new String(word.Where(Char.IsLetter).ToArray());
                    if (filteredWord.Length == 0)
                        continue;
                    outputLine += filteredWord + " : ";
                    List<string> stems = hunspell.Stem(filteredWord);
                    foreach (var stem in stems)
                    {
                        if (stems.Last() == stem)
                            outputLine += stem;
                        else
                            outputLine += stem + " , ";
                    }
                    outputFile.WriteLine(outputLine);
                    Console.WriteLine(outputLine);
                }
            }
            outputFile.Flush();
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
    }
}
